<template>
<view class="content">
		<view class="avatorWrapper">
			<view class="avator">
				<image class="img" src="../../static/logo.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="form">
			<view class="inputWrapper">
				<input class="input" id="username" v-model="username" type="text" value="" placeholder="请输入账号"/>
			</view>
			<view class="inputWrapper">
				<input class="input" id="password" v-model="password" type="password" value="" placeholder="请输入口令"/>
			</view>
			<view class="loginBtn">
				<text class="btnValue" @click="login">登录</text>
			</view>
			<view class="forgotBtn">
				<text @click="register">注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username:"",
				password:"",
				userarry:[],
				nic:""
			}
		},
		methods: {
			login:function(e){
				let usn = this.username;
				let paw = this.password;
				if(usn==''||paw==''){
					uni.showToast({title: "输入不能为空", icon:"none"});
				}else{
					uni.request({
						url: 'http://116.62.213.195/login.php',
						data:{
							method: 'login',
							username: usn,
							password: paw
						},
						header: {'content-type' : "application/x-www-form-urlencoded"},
						method:'POST',
						success: res =>{
							if(res.data.code == '200'){
						        uni.showToast({title: "登录成功", icon:"none"});
								this.userarry=JSON.parse(JSON.stringify(res.data.data));
								uni.setStorageSync('mumber',this.userarry[0].mumber);
								uni.setStorageSync('username',this.userarry[0].username);
								uni.setStorageSync('money',this.userarry[0].money);
								uni.setStorageSync('password',this.userarry[0].password);
								uni.setStorageSync('nickname',this.userarry[0].nickname);
								
								uni.switchTab({
								                    url: '../main/main'
								                });
						    }else{
						        uni.showToast({title: "登录失败，请检查用户名和密码"+res.data.data, icon:"none"});
						    }
						}
					});
				}
			},
			register:function(e){
				uni.navigateTo({
					url:'../register/register'
				})
			}
		}
	}
</script>
<style>
.content {
		background: #27a1b4;
		width: 100vw;
		height: 100vh;
	}
	.avatorWrapper{
		height: 30vh;
		width: 100vw;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}
	.avator{
		width: 200upx;
		height: 200upx;
		overflow: hidden;
	}
	.avator .img{
		width: 100%
	}
	.form{
		padding: 0 100upx;
		margin-top: 80px;
	}
	.inputWrapper{
		width: 100%;
		height: 80upx;
		background: white;
		border-radius: 20px;
		box-sizing: border-box;
		padding: 0 20px;
		margin-top: 25px;
	}
	.inputWrapper .input{
		width: 100%;
		height: 100%;
		text-align: center;
		font-size: 15px;
	}
	.loginBtn{
		width: 100%;
		height: 80upx;
		background: #38b390;
		border-radius: 50upx;
		margin-top: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
		
	}
	.loginBtn .btnValue{
		color: white;
	}
	.forgotBtn{
		text-align: center;
		color: #EAF6F9;
		font-size: 15px;
		margin-top: 20px;
	}
</style>
